using System.Configuration;

namespace Lync.Widget.Library.Configuration
{
    [ConfigurationCollection(typeof(ActivedirectoryMappingConfigurationElement))]
    public class ActivedirectoryMappingElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ActivedirectoryMappingConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            var reference = (ActivedirectoryMappingConfigurationElement)element;
            return reference.Id;
        }

        public ActivedirectoryMappingConfigurationElement this[int index]
        {
            get
            {
                return (ActivedirectoryMappingConfigurationElement)base.BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        public ActivedirectoryMappingConfigurationElement this[string name]
        {
            get
            {
                return (ActivedirectoryMappingConfigurationElement)BaseGet(name);
            }
        }

    }
}